package com.kaishengit.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.kaishengit.entity.Project;
import com.kaishengit.util.DBHelp;
import com.kaishengit.util.RowMapper;

public class ProjectDao {
	private DBHelp<Project> db = new DBHelp<Project>();

	public List<Project> findById(String id) {
		String sql = "select id,`name`,`desc`,createtime from t_project where id in(select projectid from t_employee_project where employeeid = ?)";
		
		return db.executeQueryForList(sql, new ProjectRowMapper(), id);
	}
	public boolean save(Project p) {
		String sql = "insert into t_project(id,`name`,`desc`,createtime) values(?,?,?,?)";
		return db.executeSQL(sql, p.getId(),p.getName(),p.getDesc(),p.getCreatetime());
		
	}
	

	
	
	
	
	
	private class ProjectRowMapper implements RowMapper<Project>{

		public Project mapRow(ResultSet rs) throws SQLException {
			Project p = new Project();
			p.setCreatetime(rs.getString("createtime"));
			p.setDesc(rs.getString("desc"));
			p.setId(rs.getString("id"));
			p.setName(rs.getString("name"));
			return p;
		}
		
	}
} 
